package com.guyu.app.common.biz.handler;

import com.guyu.app.common.constant.CacheKey;
import com.guyu.app.common.constant.LockKey;
import com.guyu.plugin.redisson.utils.LockUtils;
import com.guyu.plugin.redisson.utils.RedisUtils;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.springframework.stereotype.Component;

@Component
public class CacheHandler {

    /**
     * 短信验证码
     */
    public RLock getSmsCaptchaLock(String phone) {
        return LockUtils.getLockAndTry(LockKey.SMS_CAPTCHA_LOCK, phone);
    }

    /**
     * 用户验证码缓存
     */
    public RBucket<String> getSmsCaptchaCache(String phone, String serialNo) {
        return RedisUtils.getBucket(CacheKey.SMS_CAPTCHA, phone, serialNo);
    }

}
